<?php
/**
 * Created by PhpStorm.
 * User: Xwen
 * Date: 2018/12/19
 * Time: 22:13
 *
 *          ┌─┐       ┌─┐
 *       ┌──┘ ┴───────┘ ┴──┐
 *       │                 │
 *       │       ───       │
 *       │  ─┬┘       └┬─  │
 *       │                 │
 *       │       ─┴─       │
 *       │                 │
 *       └───┐         ┌───┘
 *           │         │
 *           │         │
 *           │         │
 *           │         └──────────────┐
 *           │                        │
 *           │                        ├─┐
 *           │                        ┌─┘
 *           │                        │
 *           └─┐  ┐  ┌───────┬──┐  ┌──┘
 *             │ ─┤ ─┤       │ ─┤ ─┤
 *             └──┴──┘       └──┴──┘
 *                 神兽保佑
 *                 代码无BUG!
 *"The trouble with programmers is that you can never tell what a programmer is doing until it’s too late.”- Seymour Cray
 */

namespace app\admin\controller;


class Menu extends Base
{
    public function index(){
        return $this->fetch();
    }
    public function infos(){
        $pageNumber = $this->request->get('pageNumber');
        $pageSize = $this->request->get('pageSize');
        $name = $this->request->get('name');

        $res = model('Menu', 'logic')->infos($pageNumber, $pageSize, $name);
        return $res;
    }
    public function add(){
        $data = [
            'menu_name'     =>  $this->request->post('menu_name'),
            'pid'           =>  $this->request->post('pid'),
            'menu_icon'     =>  $this->request->post('menu_icon'),
            'controller'    =>  $this->request->post('controller'),
            'method'        =>  $this->request->post('method')
        ];
        $res = model('Menu', 'logic')->add($data);
        if (!$res) {
            return [
                'status'    =>  false,
                'msg'       =>  '添加失败！'
            ];
        }
        return [
            'status'    =>  true,
            'msg'       =>  '添加成功！'
        ];
    }
    public function edit(){
        $data = [
            'id'            =>  $this->request->post('id'),
            'menu_name'     =>  $this->request->post('menu_name'),
            'pid'           =>  $this->request->post('pid'),
            'menu_icon'     =>  $this->request->post('menu_icon'),
            'controller'    =>  $this->request->post('controller'),
            'method'        =>  $this->request->post('method')
        ];
        $res = model('Menu', 'logic')->edit($data);
        if (!$res) {
            return [
                'status'    =>  false,
                'msg'       =>  '修改失败！'
            ];
        }
        return [
            'status'    =>  true,
            'msg'       =>  '修改成功！'
        ];return $res;
    }
    public function getParent(){
        return model('Menu', 'logic')->getParent();
    }
    public function getAll(){
        return model('Menu', 'logic')->getAll();
    }
    public function delete(){
        $data = [
            'id'            =>  $this->request->post('id')
        ];
        $res = model('Menu', 'logic')->delete($data);
        if (!$res) {
            return [
                'status'    =>  false,
                'msg'       =>  '删除失败！'
            ];
        }
        return [
            'status'    =>  true,
            'msg'       =>  '删除成功！'
        ];
    }

}